package net.qunzhi.modules.cms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.qunzhi.common.utils.R;
import net.qunzhi.modules.cms.service.TbCopyFlowDataService;
import net.qunzhi.modules.cms.service.TbFlowStateService;
import net.qunzhi.modules.cms.vo.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 调度中心流量数据
 *
 * @author cpk
 * @date 2021-11-08 14:20:00
 */
@Api(tags = "每日汇总相关")
@RestController
@RequestMapping("cms/dailySummary")
public class DailySummaryController {
    @Autowired
    private TbFlowStateService tbFlowStateService;
    @Autowired
    private TbCopyFlowDataService copyFlowDataService;

    /**
     * 列表
     */
    @ApiOperation("每日汇总记录列表")
    @GetMapping("/dailySummary")
    @RequiresPermissions("cms:dailySummary::list")
    public R dailySummary(String startDate ,String endDate){

        AutoAndCopyVO<XjWaterSummary> vo = new AutoAndCopyVO<XjWaterSummary>();
        List<XjWaterSummary> vo_auto= tbFlowStateService.getDailySummaryList(startDate,endDate);
        List<XjWaterSummary> vo_copy=tbFlowStateService.getCopyDailySummaryList(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("dailySummaryList", vo);
    }


    @ApiOperation("各流量计售水情况")
    @GetMapping("/waterSellConditionOfEachFlowmeter")
    @RequiresPermissions("cms:dailySummary::list")
    public R waterSellConditionOfEachFlowmeter(String startDate,String endDate){

        AutoAndCopyVO<WaterSellConditionOfEachFlowmeterVO> vo = new AutoAndCopyVO<WaterSellConditionOfEachFlowmeterVO>();
        List<WaterSellConditionOfEachFlowmeterVO> vo_auto = tbFlowStateService.getWaterSellConditionOfEachFlowmeter(startDate,endDate);
        List<WaterSellConditionOfEachFlowmeterVO> vo_copy=tbFlowStateService.getCopyWaterSellConditionOfEachFlowmeter(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("waterSellConditionOfEachFlowmeter", vo);
    }

    @ApiOperation("各片区水量占百分比")
    @GetMapping("/percentageOfWaterInEachArea")
    @RequiresPermissions("cms:dailySummary::list")
    public R percentageOfWaterInEachArea(String startDate,String endDate){
        AutoAndCopyVO<PercentageOfWaterInEachAreaVO> vo = new AutoAndCopyVO<PercentageOfWaterInEachAreaVO>();
        List<PercentageOfWaterInEachAreaVO> vo_auto = tbFlowStateService.getPercentageOfWaterInEachArea(startDate,endDate);
        List<PercentageOfWaterInEachAreaVO> vo_copy = tbFlowStateService.getCopyPercentageOfWaterInEachArea(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("percentageOfWaterInEachArea", vo);
    }


    @ApiOperation("各片区售水量汇总-每日水量汇总")
    @GetMapping("/dailyFlowOfEachArea")
    @RequiresPermissions("cms:dailySummary::list")
    public R dailyFlowOfEachArea(String startDate,String endDate){
        AutoAndCopyVO<DailyFlowOfEachAreaVO> vo = new AutoAndCopyVO<DailyFlowOfEachAreaVO>();
        List<DailyFlowOfEachAreaVO> vo_auto = tbFlowStateService.getDailyFlowOfEachArea(startDate,endDate);
        List<DailyFlowOfEachAreaVO> vo_copy = tbFlowStateService.getCopyDailyFlowOfEachArea(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("dailyFlowOfEachArea", vo);
    }


    @ApiOperation("各片区售水量汇总-每月累计水量汇总")
    @GetMapping("/monthlyCumulativeWaterOfEachArea")
    @RequiresPermissions("cms:dailySummary::list")
    public R monthlyCumulativeWaterOfEachArea(String startDate,String endDate){
        AutoAndCopyVO<MonthlyCumulativeWaterOfEachAreaVO> vo = new AutoAndCopyVO<MonthlyCumulativeWaterOfEachAreaVO>();
        List<MonthlyCumulativeWaterOfEachAreaVO> vo_auto = tbFlowStateService.getMonthlyCumulativeWaterOfEachArea(startDate,endDate);
        List<MonthlyCumulativeWaterOfEachAreaVO> vo_copy = tbFlowStateService.getCopyMonthlyCumulativeWaterOfEachArea(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("monthlyCumulativeWaterOfEachArea", vo);
    }

    @ApiOperation("各片区产销率")
    @GetMapping("/salesOutputRatioOfEachArea")
    @RequiresPermissions("cms:dailySummary::list")
    public R salesOutputRatioOfEachArea(String startDate,String endDate){
        AutoAndCopyVO<SalesOutputRatioOfEachAreaVO> vo = new AutoAndCopyVO<SalesOutputRatioOfEachAreaVO>();
        List<SalesOutputRatioOfEachAreaVO> vo_auto = tbFlowStateService.getSalesOutputRatioOfEachArea(startDate,endDate);
        List<SalesOutputRatioOfEachAreaVO> vo_copy = tbFlowStateService.getCopySalesOutputRatioOfEachArea(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("salesOutputRatioOfEachArea", vo);
    }


    @ApiOperation("各流量计凌晨时段水量")
    @GetMapping("/flowRateOfEachFlowmeterAtDawn")
    @RequiresPermissions("cms:dailySummary::list")
    public R flowRateOfEachFlowmeterAtDawn(String startDate,String endDate){
        AutoAndCopyVO<MorningWaterVO> vo = new AutoAndCopyVO<MorningWaterVO>();
        List<MorningWaterVO> vo_auto = tbFlowStateService.getFlowRateOfEachFlowmeterAtDawn(startDate,endDate);
        List<MorningWaterVO> vo_copy = tbFlowStateService.getCopyFlowRateOfEachFlowmeterAtDawn(startDate,endDate);
        vo.setAutoList(vo_auto);
        vo.setCopyList(vo_copy);
        return R.ok().put("flowRateOfEachFlowmeterAtDawn", vo);
    }

    @ApiOperation("未手抄的数据列表,包括两个无流量计的广州和紫南")
    @GetMapping("/undoCopyData")
    @RequiresPermissions("cms:dailySummary::list")
    public R undoCopyData(String startDate,String endDate){

        return R.ok().put("undoCopyData", copyFlowDataService.getUndoCopyData(startDate, endDate));
    }

}
